<?php
class Transport {
	
	/**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function addTransport($form_values)
    {
    	$type = $form_values['type'];
    	$customer = $form_values['customer'];
    	$location = $form_values['location'];
    	$distance = $form_values['distance'];
    	$rate = $form_values['rate'];
    	
    	$addRate = $this->_db->exec("
    		INSERT INTO transport_rates(type, cust_id, location, distance, rate)
    		VALUES('" . $type . "', '" . $customer . "', '" . $location . "', '" . $distance . "', '" . $rate . "')
    	");
    	
    	if($addRate) {
    		echo "Rate has been successfully added.";
    	}
    	
    }
    
    public function addUserTranspt($form_value)
    {
    	$type = $form_value['type'];
    	$customer = $form_value['customer'];
    	$amount = $form_value['amount'];
    	$userid = $form_value['userid'];
    	$distance = $form_value['distance'];
    	$rate = $form_value['rate'];
    	$hrs = $form_value['hrs'];
    	
    	if($hrs != "")
    	{
    		$net_amount = $distance * $hrs * $rate;    	
    	} else {
    		$net_amount = $amount;
    	}
    	
    	$add_usertranspt = $this->_db->exec("
    		INSERT INTO user_rates(userid, customer_id, type, amount)
    		VALUES(" . $userid . ", " . $customer . ", '" . $type . "', '" . $net_amount . "') 
    	");
    	
    	if($add_usertranspt)
    	{
    		echo "User Transport has been successfully added";
    	}
    }
}
?>